/*
 * @Author: Zcl84765
 * @Date: 2020-04-09 18:12:36
 * @LastEditors: Zcl84765
 * @LastEditTime: 2023-01-29 16:53:53
 */
import axios from 'axios'
import Vue from 'vue'
import store from '../store'
import router from '../router'
import { Message } from 'element-ui'
import { checkLoginToken, checkTokenEndTime } from './util'
axios.interceptors.request.use((req) => {
  const token = JSON.parse(sessionStorage.getItem('token')) || ''
  if (req.url != 'login') {
    if (checkLoginToken()) {
      Message.success('重新登录')
      return router.push('/login')
    }
    if (checkTokenEndTime()) {
      Message.success('登录已失效重新登录')
      return router.push('/login')
    } else {
      req.headers.Authorization = token
    }
  }
  return req
})
// 配置请求的跟路径, 目前用mock模拟数据, 所以暂时把这一项注释起来

Vue.prototype.$http = axios
